/**
 * API基础配置
 */

import { getApiBaseUrl, getRequestTimeout } from '../utils/config'

// API基础URL - 从配置文件动态获取
export const API_BASE_URL = getApiBaseUrl()

// 请求超时时间（毫秒）- 从配置文件动态获取
export const REQUEST_TIMEOUT = getRequestTimeout()

// 获取存储的token
export const getToken = (): string | null => {
  return localStorage.getItem('token')
}

// 设置token
export const setToken = (token: string): void => {
  localStorage.setItem('token', token)
}

// 移除token
export const removeToken = (): void => {
  localStorage.removeItem('token')
}

// 获取请求头
export const getHeaders = (): Record<string, string> => {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  }
  
  const token = getToken()
  if (token) {
    headers['Authorization'] = `Bearer ${token}`
  }
  
  return headers
}
